package com.baidu.mapapi;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;

public class RouteOverlay extends ItemizedOverlay<OverlayItem>
{
  private ArrayList<b> a;
  private MapView b;
  private Context c;
  private DisplayMetrics d;
  private int e;
  private HashMap<Integer, a> f;
  public MKRoute mRoute = null;

  public RouteOverlay(Activity paramActivity, MapView paramMapView)
  {
    super(null);
    this.a = null;
    this.b = null;
    this.c = null;
    this.e = 1;
    this.c = paramActivity;
    this.b = paramMapView;
    this.d = new DisplayMetrics();
    paramActivity.getWindowManager().getDefaultDisplay().getMetrics(this.d);
    if (Mj.i <= 120)
      this.e = 0;
    while (true)
    {
      while (true)
      {
        return;
        if (Mj.i > 180)
          break;
        this.e = 1;
      }
      this.e = 2;
    }
  }

  void a(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    this.f.clear();
  }

  public void animateTo()
  {
    if (size() > 0)
      onTap(0);
  }

  protected OverlayItem createItem(int paramInt)
  {
    Drawable localDrawable;
    char[] arrayOfChar = new char[3];
    arrayOfChar[0] = 108;
    arrayOfChar[1] = 109;
    arrayOfChar[2] = 104;
    String[] arrayOfString = new String[4];
    arrayOfString[0] = "start";
    arrayOfString[1] = "end";
    arrayOfString[2] = "foot";
    arrayOfString[3] = "car";
    b localb = (b)this.a.get(paramInt);
    OverlayItem localOverlayItem = new OverlayItem(localb.b, localb.a, null);
    StringBuilder localStringBuilder = new StringBuilder(32);
    if ((localb.c == 0) || (localb.c == 1))
    {
      localStringBuilder.append("icon_nav_").append(arrayOfString[localb.c]).append('_').append(arrayOfChar[this.e]).append(".png");
      localDrawable = i.a(this.c, localStringBuilder.toString());
      if ((localb.c != 0) && (localb.c != 1))
        break label234;
      localOverlayItem.setMarker(boundCenterBottom(localDrawable));
    }
    while (true)
    {
      while (true)
      {
        return localOverlayItem;
        localStringBuilder.append("icon_direction_").append(arrayOfChar[this.e]).append(".png");
        localDrawable = i.a(this.c, localStringBuilder.toString(), 30 * localb.d);
      }
      label234: localOverlayItem.setMarker(boundCenter(localDrawable));
    }
  }

  public boolean draw(Canvas paramCanvas, MapView paramMapView, boolean paramBoolean, long paramLong)
  {
    a locala1;
    a locala3;
    Projection localProjection = paramMapView.getProjection();
    ((Activity)this.c).getWindowManager().getDefaultDisplay().getMetrics(this.d);
    int i = paramMapView.getZoomLevel();
    if (this.mRoute != null)
    {
      ArrayList localArrayList1 = this.mRoute.getArrayPoints();
      ArrayList localArrayList2 = this.mRoute.a;
      if ((localArrayList1 != null) && (localArrayList1.size() > 0))
      {
        locala1 = (a)this.f.get(Integer.valueOf(i));
        if (locala1 != null)
          break label1017;
        a locala2 = new a(this);
        int j = localArrayList1.size();
        ArrayList localArrayList3 = new ArrayList();
        for (int k = 0; k < j; ++k)
        {
          i.a((ArrayList)localArrayList1.get(k), (ArrayList)localArrayList2.get(k), i, localArrayList3);
          int i16 = localArrayList3.size();
          for (int i17 = 0; i17 < i16; ++i17)
          {
            Point localPoint5 = new Point();
            paramMapView.a.a((GeoPoint)localArrayList3.get(i17), localPoint5);
            locala2.b.add(localPoint5);
          }
        }
        locala2.a.setLatitudeE6(paramMapView.getMapCenter().getLatitudeE6());
        locala2.a.setLongitudeE6(paramMapView.getMapCenter().getLongitudeE6());
        this.f.put(Integer.valueOf(i), locala2);
        locala3 = locala2;
      }
    }
    while (true)
    {
      Point localPoint1;
      Point localPoint2;
      int i5;
      int i6;
      int i7;
      int i8;
      int i9;
      int l = locala3.b.size();
      if (l > 1)
      {
        localPoint1 = new Point();
        localPoint2 = new Point();
        Paint localPaint = new Paint();
        localPaint.setAntiAlias(true);
        localPaint.setStrokeWidth(6.0F);
        localPaint.setColor(Color.rgb(58, 107, 189));
        localPaint.setAlpha(192);
        Point localPoint3 = new Point();
        Point localPoint4 = new Point();
        localProjection.toPixels(paramMapView.getMapCenter(), localPoint3);
        localProjection.toPixels(locala3.a, localPoint4);
        int i1 = localPoint3.x - localPoint4.x;
        int i2 = localPoint3.y - localPoint4.y;
        int i3 = i1 - paramMapView.b.c;
        int i4 = i2 - paramMapView.b.d;
        localPoint1.x = ((Point)locala3.b.get(0)).x;
        localPoint1.y = ((Point)locala3.b.get(0)).y;
        if (this.b.b.e != 1D)
        {
          int i14 = (int)(0.5D + (localPoint1.x - this.b.b.f) * this.b.b.e);
          int i15 = (int)(0.5D + (localPoint1.y - this.b.b.g) * this.b.b.e);
          localPoint1.x = (i14 + this.b.b.f);
          localPoint1.y = (i15 + this.b.b.g);
        }
        localPoint1.x -= i3;
        localPoint1.y -= i4;
        i5 = 1;
        i6 = 0;
        i7 = 0;
        if (i5 < l)
        {
          localPoint2.x = ((Point)locala3.b.get(i5)).x;
          localPoint2.y = ((Point)locala3.b.get(i5)).y;
          if (this.b.b.e != 1D)
          {
            int i12 = (int)(0.5D + (localPoint2.x - this.b.b.f) * this.b.b.e);
            int i13 = (int)(0.5D + (localPoint2.y - this.b.b.g) * this.b.b.e);
            localPoint2.x = (i12 + this.b.b.f);
            localPoint2.y = (i13 + this.b.b.g);
          }
          localPoint2.x -= i3;
          localPoint2.y -= i4;
          if (!(i.a(localPoint1, localPoint2, this.d.widthPixels, this.d.heightPixels)))
            break label952;
          paramCanvas.drawLine(localPoint1.x, localPoint1.y, localPoint2.x, localPoint2.y, localPaint);
          i8 = 1;
          i9 = i6;
        }
      }
      while (true)
      {
        boolean bool;
        localPoint1.x = localPoint2.x;
        localPoint1.y = localPoint2.y;
        if (i9 > 50)
        {
          if (i < 3)
            break label1000;
          bool = super.draw(paramCanvas, paramMapView, paramBoolean, paramLong);
        }
        while (true)
        {
          while (true)
          {
            while (true)
            {
              label952: int i10;
              do
              {
                return bool;
                if (i7 != 1)
                  break label1006;
                i10 = i6 + 1;
              }
              while (i10 > 50);
              int i11 = i7;
              i9 = i10;
              i8 = i11;
            }
            ++i5;
            i6 = i9;
            i7 = i8;
          }
          label1000: bool = true;
        }
        label1006: i8 = i7;
        i9 = i6;
      }
      label1017: locala3 = locala1;
    }
  }

  protected boolean onTap(int paramInt)
  {
    OverlayItem localOverlayItem = getItem(paramInt);
    this.b.getController().animateTo(localOverlayItem.mPoint);
    if (localOverlayItem.mTitle != null)
      Toast.makeText(this.c, localOverlayItem.mTitle, 1).show();
    super.onTap(paramInt);
    return true;
  }

  public void setData(MKRoute paramMKRoute)
  {
    if (paramMKRoute == null);
    while (true)
    {
      int i;
      return;
      this.mRoute = paramMKRoute;
      this.a = new ArrayList();
      if (this.mRoute.getRouteType() == 1)
        i = 3;
      while (true)
      {
        GeoPoint localGeoPoint1 = this.mRoute.getStart();
        if (localGeoPoint1 != null)
        {
          b localb1 = new b(this, null);
          localb1.b = localGeoPoint1;
          localb1.c = 0;
          this.a.add(localb1);
        }
        int j = paramMKRoute.getNumSteps();
        if (j == 0)
          break;
        if (this.a.size() > 0)
          ((b)this.a.get(0)).a = paramMKRoute.getStep(0).getContent();
        int k = 1;
        while (true)
        {
          if (k >= j - 1)
            break label210;
          MKStep localMKStep = paramMKRoute.getStep(k);
          b localb3 = new b(this, null);
          localb3.b = localMKStep.getPoint();
          localb3.a = localMKStep.getContent();
          localb3.c = i;
          localb3.d = localMKStep.a();
          this.a.add(localb3);
          ++k;
        }
        i = 2;
      }
      label210: GeoPoint localGeoPoint2 = this.mRoute.getEnd();
      if (localGeoPoint2 != null)
      {
        b localb2 = new b(this, null);
        localb2.b = localGeoPoint2;
        localb2.c = 1;
        this.a.add(localb2);
      }
      this.f = new HashMap();
      super.populate();
    }
  }

  public int size()
  {
    int i;
    if (this.a == null)
      i = 0;
    while (true)
    {
      return i;
      i = this.a.size();
    }
  }

  class a
  {
    public GeoPoint a = new GeoPoint(0, 0);
    public ArrayList<Point> b = new ArrayList();
  }

  private class b
  {
    public String a;
    public GeoPoint b;
    public int c;
    public int d;
  }
}